//
//  SerialViewController.m
//  XPhoto
//
//  Created by sentinel on 2020/4/1.
//  Copyright © 2020 baboy. All rights reserved.
//

#import "SerialEditViewController.h"
#import "MediaEditTableViewCell.h"
#import <AFNetworking/UIImageView+AFNetworking.h>
#import <AFNetworking/UIButton+AFNetworking.h>
#import "BKActionSheet.h"
#import "CoverMaskView.h"
#import "AddrSearchViewController.h"
#import <BKKit/BKNavigationController.h>
#import "AppInstruction.h"
#import "SerialInstructionTableViewCell.h"
#import "UIViewController+camera.h"
#import "SerialPostDetailViewController.h"
#import "ButtonTableViewCell.h"
#import "TextEditorViewController.h"
#import "SelectionViewController.h"
#import "SysDict.h"
#import <BKKit/BKNavigationController.h>
#import "PhotoLibViewController.h"
#import "PhotoCameraViewController.h"

#define TABLE_ROW_TITLE_INDEX 0
#define TABLE_ROW_TYPE_INDEX 1
#define TABLE_ROW_ADDR_INDEX 2
#define TABLE_ROW_INTRO_INDEX 3
#define TABLE_ROW_SUBMIT_INDEX 4

#define COVER_HEIGHT        200
#define TITLE_TAG_NAME      NSLocalizedString(@"title", @"描述")
#define TYPE_TAG_NAME       NSLocalizedString(@"type", @"描述")
#define ADDR_TAG_NAME       NSLocalizedString(@"addr", @"描述")
#define INTRO_TAG_NAME      NSLocalizedString(@"intro", @"描述")

#define ACTION_SHEET_INDEX_UPDATE_COVER_BY_TAKE_PHOTO      100
#define ACTION_SHEET_INDEX_UPDATE_COVER_BY_PHOTO_LIB       101

@interface SerialEditViewController ()<BKActionSheetDelegate, AddrSearchDelegate, TextEditorDelegate, SelectionDelegate ,UITextViewDelegate, PhotoEditDelegate, PhotoLibViewDelegate>
//@property(nonatomic, strong) MediaEditTableViewCell *titleTableViewCell;
//@property(nonatomic, strong) MediaEditTableViewCell *addrTableViewCell;
//@property(nonatomic, strong) MediaEditTableViewCell *introTableViewCell;
@property(nonatomic, strong) SerialInstructionTableViewCell *serialInstructionTableViewCell;

@property(nonatomic, strong) IBOutlet UIImageView *coverImageView;
@property(nonatomic, strong) CoverMaskView *coverMaskView;
@property(nonatomic, strong) AppInstruction *serialInstruction;
@property(nonatomic, assign) NSInteger actionSheetSelectedTag;
@property(nonatomic, strong) PhotoAsset *coverPhotoAsset;

@end

@implementation SerialEditViewController

- (id)init{
    if (self = [super initWithNibName:NSStringFromClass([self class]) bundle:nil]){
        //        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}
- (BOOL) isUpdate{
    BOOL flag = _postSerial && _postSerial.id > 0;
//    return NO;
    return flag;
}
- (User*)user{
    if(!_user){
        return [User currentUser];
    }
    return _user;
}
- (void)createCoverMaskView{
    if (!_coverMaskView) {
        _coverMaskView = [CoverMaskView newInstance];
        _coverMaskView.frame = CGRectMake(0, -self.tableView.bounds.size.height, self.tableView.bounds.size.width, self.tableView.bounds.size.height);
        _coverMaskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
        [_coverMaskView.actionButton addTarget:self action:@selector(takePhotoForCover:) forControlEvents:UIControlEventTouchUpInside];
        [self.tableView addSubview:_coverMaskView];
    }
}
- (void)loadInstruction{
    [AppInstruction searchWithKey:APP_INSTRUCTION_SERIAL_KEY
                         callback:^(id  _Nonnull task, id  _Nonnull instruction, NSError * _Nonnull error) {
        self.serialInstruction = instruction;
        [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationNone];
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.hidden = YES;
    if (!_postSerial) {
        _postSerial = [PostSerial new];
        _postSerial.type = SERIAL_TYPE_DATE;
    }
    [self createCoverMaskView];
    [self loadInstruction];
    [self.coverImageView setImageWithURL:[NSURL URLWithString:self.postSerial.cover] placeholderImage:nil];
    
    [self updateSerialTitle:self.postSerial.title];
    self.coverMaskView.userNameLabel.text = self.user?[NSString stringWithFormat:@"@%@", self.user.userName]:nil;
    self.tableView.tableFooterView = [UIView new];
    self.tableView.contentInset = UIEdgeInsetsMake(COVER_HEIGHT, 0, 0, 0);
}
- (void)updateSerialTitle:(NSString *)title{
    self.postSerial.title = title;
    self.coverMaskView.title = (self.coverPhotoAsset || self.postSerial.cover)?title:NSLocalizedString(@"click_to_setting_cover",@"系列");
}
- (void)resizeCoverImageView{
    CGFloat coverImageViewHeight = -self.tableView.contentOffset.y - (self.navigationController.navigationBar.hidden?-self.view.safeAreaInsets.top:self.tableView.safeAreaInsets.top);
    DLOG(@"resizeCoverImageView|coverImageViewHeight:%f,%@,%@", coverImageViewHeight,NSStringFromUIEdgeInsets(self.view.safeAreaInsets),NSStringFromUIEdgeInsets(self.tableView.safeAreaInsets) );
    CGRect coverImageViewFrame = self.coverImageView.superview.frame;
    coverImageViewHeight = MAX(coverImageViewHeight, COVER_HEIGHT/3);
    if (coverImageViewHeight != coverImageViewFrame.size.height) {
        coverImageViewFrame.origin.y = self.view.safeAreaInsets.top - (self.navigationController.navigationBar.hidden?self.view.safeAreaInsets.top:0);
        coverImageViewFrame.size.height = coverImageViewHeight;
        self.coverImageView.frame = coverImageViewFrame;
    }
}
- (void)viewSafeAreaInsetsDidChange{
    [super viewSafeAreaInsetsDidChange];
    [self resizeCoverImageView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self resizeCoverImageView];
}
- (void)popViewController:(id)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(serialEditViewControllerShouldQuit:)]) {
        BOOL shouldQuit = [self.delegate serialEditViewControllerShouldQuit:self];
        if (!shouldQuit) {
            return;
        }
    }
    [self.navigationController popViewControllerAnimated:YES];
}
/**
 *  上传封面
 */
- (void)uploadCover{
}
- (void)didCreatePostSerial{
    if(self.delegate && [self.delegate respondsToSelector:@selector(serialEditViewController:didCreateSerial:)]){
        [self.delegate serialEditViewController:self didCreateSerial:self.postSerial];
    }
}
/**
 * 创建系列
 */
- (void)createPostSerial:(id)button{
    [BKIndicator showMessage:NSLocalizedString(@"submitting", @"提交数据")];
    if (self.coverPhotoAsset) {
        [PostSerial createPostSerial:self.postSerial
                           withCover:self.coverPhotoAsset
                        withCallback:^(id  _Nonnull task, id  _Nullable serialId, NSError * _Nullable error) {
            if (error) {
                [BKIndicator showMessageAndFadeOut:error.localizedDescription completion:nil];
                return;
            }
            self.postSerial.id = [serialId intValue];
            [BKIndicator showMessageAndFadeOut:NSLocalizedString(@"submit_success", @"提交数据") completion:nil];
            [self didCreatePostSerial];
        }];
    }
    if (!self.coverPhotoAsset) {
        [PostSerial createPostSerial:self.postSerial
                        withCallback:^(id  _Nonnull task, id  _Nullable serialId, NSError * _Nullable error) {
            if (error) {
                [BKIndicator showMessageAndFadeOut:error.localizedDescription completion:nil];
                return;
            }
            [BKIndicator showMessageAndFadeOut:NSLocalizedString(@"submit_success", @"提交数据") completion:nil];
            self.postSerial.id = [serialId intValue];
            [self didCreatePostSerial];
        }];
    }
}
- (void)updatePostSerial{
    if ( [self isUpdate] ) {
        PostSerial *updateSerial = [PostSerial new];
        updateSerial.id = self.postSerial.id;
        updateSerial.title = self.postSerial.title;
        updateSerial.addr = self.postSerial.addr;
        updateSerial.lat = self.postSerial.lat;
        updateSerial.lng = self.postSerial.lng;
        updateSerial.intro = self.postSerial.intro;
        updateSerial.type = self.postSerial.type;
        
        [PostSerial updatePostSerial:updateSerial
                        withCallback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
            if (error) {
                [BKIndicator showMessageAndFadeOut:error.localizedDescription completion:nil];
                return;
            }
            [BKIndicator showMessageAndFadeOut:NSLocalizedString(@"submit_success", @"提交数据") completion:nil];
        }];
    }
}
/**
 * 系列介绍
 */
- (NSAttributedString *)serialInstructionString{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@""];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.paragraphSpacingBefore = 10;
    
    if ([self isUpdate]) {
        NSString *summaryText = self.postSerial.postCount>0 ? [NSString stringWithFormat:NSLocalizedString(@"serial_publish_count_format", @"系列"), self.postSerial.postCount]: NSLocalizedString(@"serial_no_published", @"系列");
        NSMutableAttributedString *summaryAttributedString = [[NSMutableAttributedString alloc] initWithString:summaryText
                                                                                             attributes:@{NSFontAttributeName:THEME_TEXT_COMMENT_FONT,
                                                                                                          NSForegroundColorAttributeName:THEME_TEXT_COLOR
                                                                                             }];
        [attributedString appendAttributedString:summaryAttributedString];
        NSAttributedString *takePhotoAttributedString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"  %@  ", NSLocalizedString(@"publish_now", @"系列")]
                                                                                        attributes:@{
                                                                                            NSFontAttributeName:THEME_TEXT_COMMENT_FONT,
                                                                                            NSForegroundColorAttributeName:THEME_TEXT_LINK_COLOR,
                                                                                            NSLinkAttributeName:APP_LINK(APP_LINK_TYPE_TAKE_PHOTO, nil)
                                                                                        }];
        
        [attributedString appendAttributedString:takePhotoAttributedString];
        [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n" attributes:@{NSParagraphStyleAttributeName:paragraphStyle}]];
    }
    
    if (self.serialInstruction) {
        NSString *text = [self.serialInstruction lang:APP_LANG_SHORT];
        
        NSMutableAttributedString *instructionAttributedString = [[NSMutableAttributedString alloc] initWithString:text
                                                                                                        attributes:@{
                                                                                                            NSFontAttributeName:THEME_TEXT_COMMENT_FONT,
                                                                                                            NSForegroundColorAttributeName:THEME_TEXT_COMMENT_COLOR,
                                                                                                            NSParagraphStyleAttributeName:paragraphStyle
                                                                                                        }];
        [attributedString appendAttributedString:instructionAttributedString];
    }
    return attributedString;
}
- (void)viewPosts{
    
    SerialPostDetailViewController * vc = [[SerialPostDetailViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - UITableViewDelegate
- (MediaEditTableViewCell *)editableTableViewCell{
    MediaEditTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MediaEditTableViewCell"];
    if (!cell) {
        cell = loadViewFromNib([MediaEditTableViewCell class], self);
    }
    return cell;
}
- (SerialInstructionTableViewCell *) serialInstructionTableViewCell{
    if (!_serialInstructionTableViewCell) {
        _serialInstructionTableViewCell = loadViewFromNib([SerialInstructionTableViewCell class], self);
        _serialInstructionTableViewCell.frame = self.view.bounds;
        _serialInstructionTableViewCell.textView.attributedText = [self serialInstructionString];
        _serialInstructionTableViewCell.textView.delegate = self;
        
    }
    return _serialInstructionTableViewCell;
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        NSInteger n = 4+([self isUpdate]?0:1);
        return n;
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == TABLE_ROW_TITLE_INDEX) {
        MediaEditTableViewCell *cell = [self editableTableViewCell];
        cell.leftImageView.image = [UIImage imageNamed:@"image.png"];
        cell.titleLabel.text = TITLE_TAG_NAME;
        cell.detailLabel.text = self.postSerial.title;
        return cell;
    }
    if (indexPath.section == 0 && indexPath.row == TABLE_ROW_TYPE_INDEX) {
        MediaEditTableViewCell *cell = [self editableTableViewCell];
        cell.leftImageView.image = [UIImage imageNamed:@"image.png"];
        cell.titleLabel.text = TYPE_TAG_NAME;
        SysDictItem *sysDictItem = [SysDict itemForValue:[@(self.postSerial.type) description] dictKey:SYS_DICT_SERIAL_TYPE_KEY];
        cell.detailLabel.text = sysDictItem.title;//[NSString stringWithFormat:@"%ld", self.postSerial.type];
        return cell;
    }
    if (indexPath.section == 0 && indexPath.row == TABLE_ROW_ADDR_INDEX) {
        MediaEditTableViewCell *cell = [self editableTableViewCell];
        cell.leftImageView.image = [UIImage imageNamed:@"image.png"];
        cell.titleLabel.text = ADDR_TAG_NAME;
        cell.detailLabel.text = self.postSerial.addr;
        return cell;
    }
    if (indexPath.section == 0 && indexPath.row == TABLE_ROW_INTRO_INDEX) {
        MediaEditTableViewCell *cell =[self editableTableViewCell];
        cell.leftImageView.image = [UIImage imageNamed:@"image.png"];
        cell.titleLabel.text = INTRO_TAG_NAME;
        cell.detailLabel.text = self.postSerial.intro;
        return cell;
    }
    if (indexPath.section == 0 && indexPath.row == TABLE_ROW_SUBMIT_INDEX) {
        ButtonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ButtonTableViewCell class])];
        if (!cell) {
            cell = loadViewFromNib([ButtonTableViewCell class], self);
            [cell.button addTarget:self action:@selector(createPostSerial:) forControlEvents:UIControlEventTouchUpInside];
        }
        
        return cell;
    }
    if (indexPath.section == 1) {
        SerialInstructionTableViewCell *cell = [self serialInstructionTableViewCell];
        cell.textView.attributedText = [self serialInstructionString];
        return cell;
    }
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && (indexPath.row == TABLE_ROW_TITLE_INDEX || indexPath.row == TABLE_ROW_INTRO_INDEX) ) {
        TextEditorViewController *vc = [[TextEditorViewController alloc] init];
        vc.tag = indexPath.row;
        vc.delegate = self;
        if (indexPath.row == TABLE_ROW_TITLE_INDEX) {
            vc.defaultText = self.postSerial.title;
        }
        if (indexPath.row == TABLE_ROW_INTRO_INDEX) {
            vc.defaultText = self.postSerial.intro;
        }
        BKNavigationController *nav = [[BKNavigationController alloc] initWithRootViewController:vc];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:nav animated:YES completion:nil];
        return;
    }
    if (indexPath.row == TABLE_ROW_TYPE_INDEX) {
        SysDict *sysDict = [SysDict dictForKey:SYS_DICT_SERIAL_TYPE_KEY];
        NSMutableArray *selections = [NSMutableArray array];
        for (SysDictItem *dictItem in sysDict.items) {
            SelectionItem *item = [[SelectionItem alloc] initWithTitle:dictItem.title value:dictItem.value];
            [selections addObject:item];
        }
        
        SelectionViewController *vc = [[SelectionViewController alloc] init];
        vc.items = selections;
        vc.delegate = self;
        vc.tag = indexPath.row;
        
        BKNavigationController *nav = [[BKNavigationController alloc] initWithRootViewController:vc];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:nav animated:YES completion:nil];
        return;
    }
    if (indexPath.section == 0 && indexPath.row == TABLE_ROW_ADDR_INDEX) {
        AddrSearchViewController *vc = [[AddrSearchViewController alloc] init];
        vc.delegate = self;
        UINavigationController *nav = [[BKNavigationController alloc] initWithRootViewController:vc];
        nav.modalPresentationStyle = UIModalPresentationOverFullScreen;
        [self presentViewController:nav
                           animated:YES
                         completion:nil];
        return;
    }
//    [self viewPosts];
}
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
    
}
#pragma TextEditorDelegate
- (void)textEditorViewControllerDidCanceledEdit:(TextEditorViewController *)vc{
    [vc dismissViewControllerAnimated:YES completion:nil];
}
- (void)textEditorViewControllerDidFinishedEdit:(TextEditorViewController *)vc{
    BOOL edit = NO;
    if (vc.tag == TABLE_ROW_TITLE_INDEX && ![vc.textView.text?:@"" isEqualToString:self.postSerial.title]) {
        self.postSerial.title = vc.textView.text;
        [self updateSerialTitle:vc.textView.text];
        edit = YES;
    }
    if (vc.tag == TABLE_ROW_INTRO_INDEX && ![vc.textView.text?:@"" isEqualToString:self.postSerial.intro]) {
        self.postSerial.intro = vc.textView.text;
        edit = YES;
    }
    if (edit && [self isUpdate]) {
        [self updatePostSerial];
    }
    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:vc.tag inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
    [vc dismissViewControllerAnimated:YES completion:nil];
}
#pragma SelectionDelegate
- (void)selectionViewController:(SelectionViewController *)vc didSelectItem:(SelectionItem *)item{
    [vc dismissViewControllerAnimated:YES completion:nil];
    self.postSerial.type = [item.value intValue];
    [self updatePostSerial];
    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:TABLE_ROW_TYPE_INDEX inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
}
- (void)selectionViewControllerDidCanceled:(SelectionViewController *)vc{
     [vc dismissViewControllerAnimated:YES completion:nil];
}
#pragma UITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction{
    if ([[URL host] isEqualToString:APP_LINK_TYPE_TAKE_PHOTO]) {
        [self takePhoto];
    }
    return YES;;
}
#pragma AddrSearchDelegate
- (void)addrSearchViewController:(id)vc didSelectPlace:(BKPlace *)place{
    self.postSerial.addr = place.name;
    self.postSerial.lat = place.lat;
    self.postSerial.lng = place.lng;
    
    if([self isUpdate]){
        [self updatePostSerial];
    }
    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:TABLE_ROW_ADDR_INDEX inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
}
#pragma UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    DLOG(@"%@", NSStringFromCGPoint(scrollView.contentOffset));
    [self resizeCoverImageView];
}
#pragma takePhoto
- (void)takePhotoForCover:(id)btn{
    BKActionSheet *actionSheet = [[BKActionSheet  alloc] initWithTitle:NSLocalizedString(@"change_cover", @"按钮")
                                                                 items:@[@{
                                                                     @"title":NSLocalizedString(@"photo", @"按钮"),
                                                                     @"subtitle":NSLocalizedString(@"select_from_photo_lib", @"按钮"),
                                                                     @"tag":@ACTION_SHEET_INDEX_UPDATE_COVER_BY_PHOTO_LIB
                                                                     },
                                                                 @{
                                                                     @"title":NSLocalizedString(@"take_photo", @"按钮"),
                                                                     @"tag":@ACTION_SHEET_INDEX_UPDATE_COVER_BY_TAKE_PHOTO
                                                                     }]
                                                              delegate:self
                                                     cancelButtonTitle:NSLocalizedString(@"cancel", @"按钮")
                                                destructiveButtonTitle:nil];
    [actionSheet show];
}
- (void)actionSheet:(BKActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex data:(id)data{
    NSInteger tag = [[data valueForKey:@"tag"] intValue];
    self.actionSheetSelectedTag = tag;
    
    if (tag == ACTION_SHEET_INDEX_UPDATE_COVER_BY_TAKE_PHOTO) {
        PhotoCameraViewController *imagePicker = [PhotoCameraViewController imagePickerControllerForTakePicture];
        imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
        imagePicker.photoEditDelegate = self;
        imagePicker.edit = YES;
        [self presentViewController:imagePicker animated:YES completion:^{
            
        }];
        return;
    }
    if (tag == ACTION_SHEET_INDEX_UPDATE_COVER_BY_PHOTO_LIB) {
        PhotoLibViewController *vc = [[PhotoLibViewController alloc] init];
        vc.maxSelectedCount = 1;
        vc.delegate = self;
        BKNavigationController *nav = [[BKNavigationController alloc] initWithRootViewController:vc];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:nav animated:YES completion:^{
            
        }];
        return;
    }
    [super actionSheet:actionSheet clickedButtonAtIndex:buttonIndex data:data];
}
- (void)photoLibViewController:(id)photoLibViewController didSelectPhotos:(NSArray<PhotoAsset *> *)photoAssets{
    if (!photoAssets || photoAssets.count == 0) {
        return;
    }
    
    PhotoAsset *photoAsset = photoAssets.firstObject;
    [self.coverImageView setImageWithURL:[NSURL fileURLWithPath:photoAsset.originPath]];
    self.coverPhotoAsset = photoAsset;
    
    if ([self isUpdate] &&
        (self.actionSheetSelectedTag == ACTION_SHEET_INDEX_UPDATE_COVER_BY_TAKE_PHOTO ||
        self.actionSheetSelectedTag == ACTION_SHEET_INDEX_UPDATE_COVER_BY_PHOTO_LIB ) ) {
        [BKIndicator showTips:NSLocalizedString(@"uploading", @"提交数据")
                       inView:self.view
                     duration:0
                   completion:nil];
        [PostSerial updateCover:photoAsset
                      forSerial:self.postSerial.id
            photoUploadProgress:nil
                       callback:^(id _Nonnull task, PostSerial *serial, NSError * _Nullable error) {
            if (error) {
                [BKIndicator showTips:error.localizedDescription
                               inView:self.view
                             duration:0.1
                           completion:nil];
                return;
            }
            if (serial && serial.cover) {
                self.postSerial.cover = serial.cover;
                self.postSerial.coverThumb = serial.coverThumb;
            }
            [BKIndicator showTips:NSLocalizedString(@"submit_success", @"提交数据")
                           inView:self.view
                         duration:1.0
                       completion:nil];
        }];
        return;
    }
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
